<?php

namespace App\Http\Controllers\Api\User;

use App\Http\Controllers\Controller;
use App\Models\UserVerifyInfo;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class VerifyController extends Controller
{
    public function personalVerify(Request $request): JsonResponse
    {
        $rule        = [
            "user_id"   => "required|integer",
            "real_name" => "required|string",
            "id_card"   => "required|string",
        ];
        $input       = $request->input();
        $validateRet = Validator::make($input, $rule);
        if ($validateRet->fails()) {
            return result(1, $validateRet->errors()->first());
        }

        // 2. 入库
        try {
            UserVerifyInfo::query()->insertGetId($input);
        } catch (\Exception $e) {
            return result(1, $e->getMessage());
        }
        return result(0, '发布成功');
    }

    public function businessVerify(Request $request): JsonResponse
    {
        $rule        = [
            "user_id"           => "required|integer",
            "real_name"         => "required|string",
            "id_card"           => "required|string",
            "business_license"  => "required|string",
            "power_of_attorney" => "required|string"
        ];
        $input       = $request->input();
        $validateRet = Validator::make($input, $rule);
        if ($validateRet->fails()) {
            return result(1, $validateRet->errors()->first());
        }

        // 2. 入库
        try {
            UserVerifyInfo::query()->insertGetId($input);
        } catch (\Exception $e) {
            return result(1, $e->getMessage());
        }
        return result(0, '发布成功');
    }
}
